#include "app/app_message.h"
#include "thirdparty/log.h"
#include <assert.h>
#include <string.h>

int main(void)
{
    unsigned char data[] = {0x01, 0x02, 0x04, 0x00, 0x01, 0xEA, 0xAC, 0x22, 0x88};
    Message message;
    unsigned char result[9];
    char json_str[1024];
    app_message_initByBinary(&message, data, sizeof(data));

    printf("id_len=%d, data_len=%d\n", message.id_len, message.data_len);
    printf("payload=%02X %02X %02X %02X %02X %02X\n",
        message.payload[0], message.payload[1],
        message.payload[2], message.payload[3],
        message.payload[4], message.payload[5]);

    app_message_saveJson(&message, json_str, sizeof(json_str));
    log_info("%s", json_str);

    Message message2;
    app_message_initByJson(&message2, json_str, strlen(json_str));
    app_message_saveBinary(&message2, result, sizeof(data));

    printf("result=%02X %02X %02X %02X %02X %02X %02X %02X %02X\n",
        result[0], result[1], result[2], result[3],
        result[4], result[5], result[6], result[7], result[8]);

    assert(memcmp(data, result, 9) == 0);

    app_message_free(&message);
    app_message_free(&message2);
}